# author: axin
# date: 2021/4/21 19:43
# description:
from rest_framework import serializers

from goods.models import SPUSpecification, SPU


class SpecsSerialzier(serializers.ModelSerializer):
    """
        规格序列化器
    """
    # 指定关联外键返回数据形式
    spu = serializers.StringRelatedField(read_only=True)  # 返回名称
    spu_id = serializers.IntegerField()  # 返回id值

    class Meta:
        model = SPUSpecification
        fields = "__all__"


class SPUSerializer(serializers.ModelSerializer):
    """
        SPU序列化器
    """

    class Meta:
        model = SPU
        fields = ('id', "name")
